window.et = {};window.__extends = (this && this.__extends) || (function () {
    var extendStatics = Object.setPrototypeOf ||
        ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
        function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __generator = (this && this.__generator) || function (thisArg, body) {
    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
    return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
    function verb(n) { return function (v) { return step([n, v]); }; }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while (_) try {
            if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [op[0] & 2, t.value];
            switch (op[0]) {
                case 0: case 1: t = op; break;
                case 4: _.label++; return { value: op[1], done: false };
                case 5: _.label++; y = op[1]; op = [0]; continue;
                case 7: op = _.ops.pop(); _.trys.pop(); continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                    if (t[2]) _.ops.pop();
                    _.trys.pop(); continue;
            }
            op = body.call(thisArg, _);
        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
    }
};

(function (et) {
    var app = (function (_super) {
        __extends(app, _super);
        function app() {
            var _this = _super !== null && _super.apply(this, arguments) || this;
            _this.appInfoCache = {};
            _this.bannerHasError = false;
            _this._lastTimer = 0;
            return _this;
        }
        app.prototype.init = function (stage) {
            app.instance = this;
            this.stage = stage;
            this.checkPlatform();
            this.listenLifeCycle();
        };
        app.prototype.initApp = function (appInfo) {
            if (this.appInfoCache[appInfo.platform])
                throw "不允许对同一平台多次设置广告信息" + appInfo.platform;
            this.appInfoCache[appInfo.platform] = appInfo;
        };
        app.prototype.getAppInfo = function (platform) {
            if (platform) {
                return this.appInfoCache[platform];
            }
            return this.appInfoCache[this.platform];
        };
        app.prototype.showBannerAd = function () {
            return __awaiter(this, void 0, void 0, function () {
                var _this = this;
                return __generator(this, function (_a) {
                    switch (_a.label) {
                        case 0:
                            if (!this.adBanner) {
                                this.adBanner = api.createBannerAd({
                                    adUnitId: this.getAppInfo().bannerId,
                                    style: {
                                        left: 0,
                                        top: this.systemInfo.screenHeight,
                                        width: this.systemInfo.screenWidth * 4 / 5,
                                        height: 120
                                    }
                                });
                                this.adBanner.onError(function (res) {
                                    _this.bannerHasError = true;
                                });
                                this.adBanner.onLoad(function () {
                                    _this.bannerHasError = false;
                                });
                                this.adBanner.onResize(function (size) {
                                    var sysInfo = _this.systemInfo;
                                    _this.adBanner.style.left = sysInfo.screenWidth / 2 - size.width / 2;
                                    _this.adBanner.style.top = sysInfo.screenHeight - 1.2 * size.height;
                                });
                            }
                            if (!this.adBanner) return [3, 2];
                            return [4, this.adBanner.show()];
                        case 1:
                            _a.sent();
                            _a.label = 2;
                        case 2: return [2];
                    }
                });
            });
        };
        app.prototype.checkPlatform = function () {
            return __awaiter(this, void 0, void 0, function () {
                var _a;
                return __generator(this, function (_b) {
                    switch (_b.label) {
                        case 0:
                            if (window["wx"]) {
                                window["api"] = window["wx"];
                                this.platform = Platform.Wxgame;
                                return [2];
                            }
                            if (window["qq"]) {
                                window["api"] = window["qq"];
                                this.platform = Platform.QQ;
                                return [2];
                            }
                            if (window["tt"]) {
                                window["api"] = window["tt"];
                                this.platform = Platform.TT;
                                return [2];
                            }
                            if (window["qg"]) {
                                window["api"] = window["qg"];
                                this.platform = Platform.Vivo;
                                return [2];
                            }
                            _a = this;
                            return [4, api.getSystemInfoSync()];
                        case 1:
                            _a.systemInfo = _b.sent();
                            return [2];
                    }
                });
            });
        };
        app.prototype.listenLifeCycle = function () {
            api.onShow(this.EtOnShow);
            api.onHide(this.EtOnHide);
        };
        app.prototype.EtOnShow = function (res) {
            egret.ticker.resume();
            egret.startTick(this.refresh, this);
            this.dispatchEvent(new egret.Event(egret.Event.ACTIVATE, true, true, res));
        };
        app.prototype.EtOnHide = function () {
            this.dispatchEvent(new egret.Event(egret.Event.DEACTIVATE));
            egret.stopTick(this.refresh, this);
            egret.callLater(egret.ticker.pause, this);
        };
        app.prototype.refresh = function (stepTime) {
            if (stepTime - this._lastTimer < 2000)
                return false;
            this._lastTimer = stepTime;
            egret.sys.systemRenderer["canvasRenderer"] = null;
            egret.sys.systemRenderer["canvasRenderBuffer"] = null;
            egretUtils.cleanText(this.stage);
        };
        app.version = "1.0.0";
        app.resVersion = "1.0.0";
        return app;
    }(egret.EventDispatcher));
    et.app = app;
    var AppInfo = (function () {
        function AppInfo(platform) {
            this.platform = platform;
        }
        return AppInfo;
    }());
    et.AppInfo = AppInfo;
    var Platform;
    (function (Platform) {
        Platform[Platform["Wxgame"] = 0] = "Wxgame";
        Platform[Platform["QQ"] = 1] = "QQ";
        Platform[Platform["TT"] = 2] = "TT";
        Platform[Platform["Vivo"] = 3] = "Vivo";
    })(Platform = et.Platform || (et.Platform = {}));
})(et || (et = {}));

(function (et) {
    var egretRes = (function () {
        function egretRes() {
        }
        egretRes.pushRes = function (name, progressFunc, completeFunc, errorFunc) {
            var resEvent = new ResEvent();
            resEvent.progress = progressFunc;
            resEvent.complete = completeFunc;
            resEvent.error = errorFunc;
            if (this.ResList[name]) {
                throw "资源组重复添加" + name;
            }
            this.ResList[name] = resEvent;
        };
        egretRes.loadRes = function (clearRes) {
            if (clearRes === void 0) { clearRes = false; }
            return __awaiter(this, void 0, void 0, function () {
                var _a, _b, _i, k, resEvent;
                return __generator(this, function (_c) {
                    switch (_c.label) {
                        case 0:
                            _a = [];
                            for (_b in this.ResList)
                                _a.push(_b);
                            _i = 0;
                            _c.label = 1;
                        case 1:
                            if (!(_i < _a.length)) return [3, 4];
                            k = _a[_i];
                            resEvent = this.ResList[k];
                            return [4, this.registerResEvent(k, resEvent)];
                        case 2:
                            _c.sent();
                            if (clearRes) {
                                delete this.ResList[k];
                            }
                            _c.label = 3;
                        case 3:
                            _i++;
                            return [3, 1];
                        case 4: return [2];
                    }
                });
            });
        };
        egretRes.registerResEvent = function (resName, resEvent) {
            return __awaiter(this, void 0, void 0, function () {
                var onResProgress, onResError, onResComplete;
                return __generator(this, function (_a) {
                    switch (_a.label) {
                        case 0:
                            onResProgress = function (event) {
                                if (resEvent.progress)
                                    resEvent.progress(event);
                            };
                            onResError = function (event) {
                                if (resEvent.error)
                                    resEvent.error(event);
                            };
                            onResComplete = function (event) {
                                if (resEvent.complete)
                                    resEvent.complete(event);
                            };
                            RES.removeEventListener(RES.ResourceEvent.GROUP_PROGRESS, onResProgress, this);
                            RES.removeEventListener(RES.ResourceEvent.GROUP_LOAD_ERROR, onResError, this);
                            RES.removeEventListener(RES.ResourceEvent.GROUP_COMPLETE, onResComplete, this);
                            RES.addEventListener(RES.ResourceEvent.GROUP_PROGRESS, onResProgress, this);
                            RES.addEventListener(RES.ResourceEvent.GROUP_LOAD_ERROR, onResError, this);
                            RES.addEventListener(RES.ResourceEvent.GROUP_COMPLETE, onResComplete, this);
                            if (!!RES.isGroupLoaded(resName)) return [3, 2];
                            return [4, RES.loadGroup(resName)];
                        case 1:
                            _a.sent();
                            _a.label = 2;
                        case 2: return [2];
                    }
                });
            });
        };
        egretRes.ResList = {};
        return egretRes;
    }());
    et.egretRes = egretRes;
    var ResEvent = (function () {
        function ResEvent() {
        }
        return ResEvent;
    }());
    et.ResEvent = ResEvent;
})(et || (et = {}));
var egretUtils = (function () {
    function egretUtils() {
    }
    egretUtils.cleanText = function (container) {
        var children = container.$children;
        var length = children.length;
        for (var i = 0; i < length; ++i) {
            var child = children[i];
            if (child.$children && child.$children.length) {
                this.cleanText(child);
            }
            else if (child.$renderNode) {
                var textNode = void 0;
                if (child.$renderNode instanceof egret.sys.TextNode) {
                    textNode = child.$renderNode;
                }
                else if (child.$renderNode instanceof egret.sys.GroupNode && child.$renderNode.drawData[0] instanceof egret.sys.TextNode) {
                    textNode = child.$renderNode.drawData[0];
                }
                if (textNode) {
                    textNode.clean();
                }
            }
        }
    };
    return egretUtils;
}());
